import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', () => {
  /**
   * 登录后获取到的信息
   */
  const userInfo = ref({})
  const token = ref(undefined)

  // 存储个人信息
  const setUserInfo = (payload) => {
    userInfo.value = payload
  }
  // 删除个人信息
  const removeUserInfo = () => {
    userInfo.value = {}
  }

  // 存储token
  const setToken = (payload) => {
    token.value = payload
  }
  // 删除个人信息
  const deleteToken = () => {
    token.value = undefined
  }
  return { userInfo, setUserInfo, removeUserInfo, token, setToken, deleteToken }
},
  {
    persist: {
      key: "user",
      paths: ["userInfo", 'token']
    }
  }
)
